home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / idl / nsIPluginHost.idl < prev    next >
Text File  |  2006-05-08  |  6KB  |  147 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #include "nspluginroot.idl"
  39. #include "nsIFactory.idl"
  40. #include "nsIPluginInstanceOwner.idl"
  41. #include "nsIStreamListener.idl"
  42. #include "nsIStringStream.idl"
  43.  
  44. %{C++
  45. #include "nsplugindefs.h"
  46. #include "nsString.h"
  47. #include "nsNetUtil.h"
  48. #include "prlink.h"  // for PRLibrary
  49. %}
  50.  
  51. interface nsIPlugin;
  52. interface nsIURI;
  53. interface nsIDOMPlugin;
  54.  
  55. [ptr] native PRLibraryPtr(PRLibrary);
  56. [ref] native nsIStreamListenerRef(nsIStreamListener *);
  57.  
  58. [uuid(e740d8c4-fd94-456a-9506-9e044c5da27a)]
  59. interface nsIPluginHost : nsIFactory
  60. {
  61.   void init();
  62.  
  63.   void destroy();
  64.  
  65.   void loadPlugins();
  66.   
  67.   void getPluginFactory(in string aMimeType, out nsIPlugin aPlugin);
  68.  
  69.   void instantiateEmbeddedPlugin(in string aMimeType, in nsIURI aURL, in nsIPluginInstanceOwner aOwner);
  70.  
  71.   void instantiateFullPagePlugin(in string aMimeType, in nsIURI aURI, in nsIStreamListenerRef aStreamListener, in nsIPluginInstanceOwner aOwner);
  72.  
  73.   void setUpPluginInstance(in string aMimeType, in nsIURI aURL, in nsIPluginInstanceOwner aOwner);
  74.  
  75.   void isPluginEnabledForType(in string aMimeType);
  76.  
  77.   void isPluginEnabledForExtension(in string aExtension, in constCharStarRef aMimeType);
  78.  
  79.   readonly attribute unsigned long pluginCount;
  80.   
  81.   [noscript] void getPlugins(in unsigned long aPluginCount, out /*array*/ nsIDOMPlugin aPluginArray);
  82.  
  83.   void stopPluginInstance(in nsIPluginInstance aInstance);
  84.  
  85.   void handleBadPlugin(in PRLibraryPtr aLibrary, in nsIPluginInstance instance);
  86. };
  87.  
  88. %{C++
  89. /**
  90.  * Used for creating the correct input stream for plugins
  91.  * We can either have raw data (with or without \r\n\r\n) or a path to a file (but it must be native!)
  92.  * When making an nsIInputStream stream for the plugins POST data, be sure to take into 
  93.  * account that it could be binary and full of nulls, see bug 105417. Also, we need 
  94.  * to make a copy of the buffer because the plugin may have allocated it on the stack.
  95.  * For an example of this, see Shockwave registration or bug 108966
  96.  * We malloc only for headers here, buffer for data itself is malloced by ParsePostBufferToFixHeaders()
  97.  */
  98.  
  99. inline nsresult
  100. NS_NewPluginPostDataStream(nsIInputStream **result,
  101.                            const char *data,
  102.                            PRUint32 contentLength,
  103.                            PRBool isFile = PR_FALSE,
  104.                            PRBool headers = PR_FALSE)
  105. {
  106.   nsresult rv = NS_ERROR_UNEXPECTED;
  107.   if (!data)
  108.     return rv;
  109.  
  110.   if (!isFile) { // do raw data case first
  111.     if (contentLength < 1)
  112.       return rv;
  113.     
  114.     char *buf = (char*) data;
  115.     if (headers) {
  116.       // in assumption we got correctly formated headers just passed in
  117.       if (!(buf = (char*)nsMemory::Alloc(contentLength)))
  118.         return NS_ERROR_OUT_OF_MEMORY;
  119.       memcpy(buf, data, contentLength);
  120.     }
  121.     nsCOMPtr<nsIStringInputStream> sis = do_CreateInstance("@mozilla.org/io/string-input-stream;1",&rv);
  122.     if (NS_SUCCEEDED(rv)) {
  123.       sis->AdoptData(buf, contentLength);  // let the string stream manage our data
  124.       rv = CallQueryInterface(sis, result);
  125.     }
  126.     else if (headers)
  127.       nsMemory::Free(buf); // Cleanup the memory if the data was copied.
  128.   } else {
  129.     nsCOMPtr<nsILocalFile> file; // tmp file will be deleted on release of stream
  130.     nsCOMPtr<nsIInputStream> fileStream;
  131.     if (NS_SUCCEEDED(rv = NS_NewNativeLocalFile(nsDependentCString(data), PR_FALSE, getter_AddRefs(file))) &&
  132.         NS_SUCCEEDED(rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream),
  133.                                      file,
  134.                                      PR_RDONLY,
  135.                                      0600,
  136.                                      nsIFileInputStream::DELETE_ON_CLOSE |
  137.                                      nsIFileInputStream::CLOSE_ON_EOF))
  138.                                      ) 
  139.     {
  140.       // wrap the file stream with a buffered input stream
  141.       return NS_NewBufferedInputStream(result, fileStream, 8192);
  142.     }
  143.   }
  144.   return rv;
  145. }
  146. %}
  147.